<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/21
 * Time: 16:21
 */
header('Content-Type:application/json');
include '../classes/logincheck.php';
include '../classes/conn.php';
if(islogin()!='teacher_login') {
    die("error");
}
$leavemessage=array();
$query="select * from leavemessage where teacher='{$_SESSION['t_num']}' order by time desc";
$res=mysql_query($query);
while ($row=mysql_fetch_assoc($res)){
    $leavemessage[]=$row;
}


for($i=0;$i<count($leavemessage);$i++){

    //查询姓名
    $query="select name from student where num='{$leavemessage[$i]['student']}' and class='{$leavemessage[$i]['class']}'";
    $res=mysql_query($query);
    $row=mysql_fetch_assoc($res);
    $leavemessage[$i]['stu_name']=$row['name'];

//    查询是否回复，如果已回复将已回复的内容加入数组
    $query="select * from reply where leavemessage='{$leavemessage[$i]['Id']}'";
    $res=mysql_query($query);
    if (mysql_num_rows($res)){
        $row=mysql_fetch_assoc($res);
        $leavemessage[$i]['reply']=$row['detail'];
        $leavemessage[$i]['re_time']=$row['time'];
    }
}

$data=json_encode($leavemessage);
echo $data;